package com.mdxx.xczd.ui.presenter;

import com.mdxx.xczd.app.App;
import com.mdxx.xczd.bean.UserBean;
import com.mdxx.xczd.bean.UserBeanResult;
import com.mdxx.xczd.ui.contract.LoginContract;
import com.mdxx.xczd.utils.ToastUtil;
import rx.Observer;

/**
 * Created by MD-02 on 2017/1/13.
 */

public class LoginPresenter extends LoginContract.Presenter{
    @Override
    public void getLoginRequest(String username, String password) {
        mModel.getLoginData(username, password)
                .subscribe(new Observer<UserBeanResult>() {
            @Override
            public void onCompleted() {}

            @Override
            public void onError(Throwable e) {
                ToastUtil.showShort(e.getMessage());
            }

            @Override
            public void onNext(UserBeanResult userBeanResult) {
                if("0".equals(userBeanResult.code)){
                    UserBean userBean = userBeanResult.data;
                    App.userBean = userBean;
                    App.USERID = userBean.empNum;
                    ToastUtil.showShort("登录成功");
                    mView.returnLoginData();
                }else{
                    ToastUtil.showShort(userBeanResult.errorMsg);
                }
            }
        });
    }
}
